package com.youlu.campus.service.vote;

import com.youlu.campus.service.course.QueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author : [dengbo]
 * @className : SimpleActivityService
 * @description : [描述说明该类的功能]
 * @createTime : [2022/7/8 11:49]
 */
@Service
@Slf4j
public class SimpleActivityService {
    @Autowired
    private MongoTemplate mongoTemplate;

    public <T> T findFieldsById(String activityId, List<String> fields, Class<T> tclass) {
        QueryWrapper activeQuery = new QueryWrapper();
        activeQuery.select(fields);
        activeQuery.where("id", activityId);
        T activityInfo = mongoTemplate.findOne(activeQuery, tclass);
        return activityInfo;
    }

    public <T> List<T> selectFieldsList(List<String> activityIdList, List<String> fields, Class<T> tclass) {
        QueryWrapper activeQuery = new QueryWrapper();
        activeQuery.select(fields);
        activeQuery.in("id", activityIdList);
        return mongoTemplate.find(activeQuery, tclass);
    }
}
